<?php 
	namespace app\home\controller;

	use think\Controller;

	use think\Input;

	use think\Db;

	use think\Request;

	use think\Session;

	class Cydia extends Controller{

		//渲染页面
		public function index(){  
			return $this->fetch();
		}	

		//将添加地址的数据添加到数据库中
		public function add(Request $request){//具体的使用方法

			$user = Session('userad');

			if(request()->isPost()){

				$receive = input('post.');
		
				$a = db('address')->where('user_id',$user['user_id'])->select();	
			
				if(count($a)>=3){
					
					return ['code'=>0,'msg'=>'不能超过3条'];
					
				}else{
		            

		            $receive['user_id']=$user['user_id'];
		            $receive['ismr']=0;
		        	
		        	$sql=db('address')->insert($receive);       	
		        	
		        	if($sql){
		        		return ['code'=>1,'msg'=>'保存成功'];
		        	}else{
						return ['code'=>0,'msg'=>'保存失败'];     		
		        	}

				}
	        	
			}else{
				return ['code'=>0,'msg'=>'网络错误'];
			} 
			
	    }

	}
 ?>